<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="物料号" prop="materialCode">
        <el-input
          v-model.trim="queryParams.materialCode"
          placeholder="请输入物料号"
          clearable
          @keyup.enter="handleQuery"
          style="width: 175px"
        />
      </el-form-item>
      <el-form-item label="出库需求数" prop="requireNum">
        <el-input
          v-model.trim="queryParams.requireNum"
          placeholder="请输入出库需求数"
          clearable
          @keyup.enter="handleQuery"
          style="width: 175px"
        />
      </el-form-item>
      <el-form-item label="生产线" prop="productionLine">
        <el-input
          v-model.trim="queryParams.productionLine"
          placeholder="请输入生产线"
          clearable
          @keyup.enter="handleQuery"
          style="width: 175px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->
    <el-card style="margin-bottom: 20px;">
      <el-descriptions column="3">
        <template #title>
          <div class="card-title"><span>任务单号 {{ header.outboundOrderCode }}</span></div>
        </template>
        <el-descriptions-item>
          <template #label><span class="card-content">单据类型</span></template><span class="card-content">{{ header.type }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label><span class="card-content">紧急程度</span></template><span class="card-content">{{ header.priority  }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label><span class="card-content">创建时间</span></template><span class="card-content">{{ parseTime(header.createTime) }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label><span class="card-content">出库Port</span></template>
          <span class="card-content">{{ header.port }}</span>
        </el-descriptions-item>
        <el-descriptions-item v-if="detailList.length === 0">
          <span class="card-content" style="color: #E6A23C;font-weight: 600;">该出库单未开启!</span>
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
    <!-- <el-descriptions column="3" direction="vertical" border>
      <el-descriptions-item
        :rowspan="3"
        :width="200"
        align="center"
      >
        <template #label><span class="card-content">任务状态</span></template>
        <el-result
          icon="warning"
          title="该出库单未开启!"
        >
        </el-result>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label><span class="card-content">任务单号</span></template><span class="card-content">{{ header.outboundOrderCode }}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label><span class="card-content">单据类型</span></template><span class="card-content">{{ header.type }}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label><span class="card-content">紧急程度</span></template><span class="card-content">{{ header.priority  }}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label><span class="card-content">创建时间</span></template><span class="card-content">{{ parseTime(header.createTime) }}</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label><span class="card-content">出库Port</span></template>
        <span class="card-content">{{ header.port }}</span>
      </el-descriptions-item>
    </el-descriptions> -->
    <!-- 标题 -->
    <span style="font-size: x-large;font-weight: 600;">出库</span>
    <el-table v-loading="secondLoading" :data="bodyList" size="small">
      <el-table-column label="物料号" align="center" prop="materialCode" />
      <el-table-column label="物料名称" align="center" prop="" />
      <el-table-column label="物料类型" align="center" prop="" />
      <el-table-column label="应发数量" align="center" prop="" />
      <el-table-column label="单位" align="center" prop="" />
      <el-table-column label="已发数量" align="center" prop="" />
      <el-table-column label="待发数量" align="center" prop="" />
    </el-table>
    <pagination
      style="margin-bottom: 50px;"
      v-show="total>0"
      :total="total"
      :page-sizes="[10, 30, 50, 100]"
          v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 标题 -->
    <div v-if="detailList.length > 0">
      <span style="font-size: x-large;font-weight: 600;">出库明细</span>
      <el-table v-loading="secondLoading" :data="detailList" size="small" >
        <el-table-column label="物料号" align="center" prop="materialCode" />
        <el-table-column label="物料名称" align="center" prop="" />
        <el-table-column label="ReelID" align="center" prop="" />
        <el-table-column label="物料类型" align="center" prop="" />
        <el-table-column label="D/C" align="center" prop="" />
        <el-table-column label="数量" align="center" prop="" />
        <el-table-column label="单位" align="center" prop="" />
        <el-table-column label="箱号" align="center" prop="" />
        <el-table-column label="储格" align="center" prop="" />
      </el-table>
      <pagination
        v-show="secondTotal>0"
        :total="secondTotal"
        v-model:page="queryDetailParams.pageNum"
        v-model:limit="queryDetailParams.pageSize"
        @pagination="getListDetail"
      />
    </div>
  </div>
</template>

<script setup name="Body">
import { listHeader } from "@/api/work/outboundOrder"
import { listBody, detailAPI, getBody, delBody, addBody, updateBody } from "@/api/work/outboundDetail"

const { proxy } = getCurrentInstance()
const route = useRoute()
const header = ref([])
const bodyList = ref([])
const detailList = ref([])
const loading = ref(true)
const secondLoading = ref(false)
const showSearch = ref(true)
const total = ref(0)
const secondTotal = ref(0)

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    materialCode: null,
    requireNum: null,
    status: null,
    productionLine: null,
    outboundOrderCode: route.query.outboundOrderCode || null
  },
  queryDetailParams: {
    pageNum: 1,
    pageSize: 10,
    materialCode: null,
    requireNum: null,
    status: null,
    productionLine: null,
    outboundOrderCode: route.query.outboundOrderCode || null
  },
  rules: {
  }
})

const { queryParams, queryDetailParams, rules } = toRefs(data)

function getHeader() {
  listHeader({
    pageNum: 1,
    pageSize: 10,
    outboundOrderCode: route.query.outboundOrderCode || null
  }).then(res => {
    header.value = res.data.page.records[0]
    // console.log(header.value)
  })
}

/** 查询出库单体列表 */
function getList() {
  loading.value = true
  listBody(queryParams.value).then(res => {
    if (res.errCode === '1') {
      bodyList.value = res.data.page.records
      total.value = res.data.page.total
      loading.value = false
    }
  })
}

function getListDetail() {
  // loading.value = true
  detailAPI(queryDetailParams.value).then(res => {
    if (res.errCode === '1') {
      // console.log(res)
      // bodyList.value = res.data.page.records
      // total.value = res.data.page.total
      // loading.value = false
    }
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

getHeader()
getList()
getListDetail()
</script>

<style lang="scss" scoped>
.card-title {
  font-size: x-large;
}
.card-content {
  font-size: x-large;
}
</style>
